package com.bto.solar.work.controller;

import com.bto.solar.work.common.R;
import com.bto.solar.work.entity.Banner;
import com.bto.solar.work.service.BtoBannerService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 王小波
 * @description:   首页轮播图
 * @date 2023/9/12 10:52
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BtoBannerService btoBannerService;
    @ApiModelProperty("新增banner")
    @PostMapping("add")
    public R add(@RequestBody Banner banner)  {
        btoBannerService.addBanner(banner);
        return R.ok();
    }

    @ApiModelProperty("删除banner")
    @DeleteMapping("delete")
    public R delete(@RequestParam Integer bannerId)  {
        btoBannerService.deleteBanner(bannerId);
        return R.ok();
    }

    @ApiModelProperty("更新banner")
    @PutMapping("update")
    public R delete(@RequestBody Banner banner)  {
        btoBannerService.updateBanner(banner);
        return R.ok();
    }

    @ApiModelProperty("查询banner")
    @GetMapping("get")
    public R get(@RequestParam @NotBlank String type)  {
        return R.ok(btoBannerService.getBanner(type));
    }

}
